import 'package:aihu_getx_app/app/modules/d/d_member/d_member_vipuser_index/controllers/d_member_vipuser_index_controller.dart';
import 'package:aihu_getx_app/app/modules/d/d_member/d_member_vipuser_index/models/vip_user_resp_vo.dart';
import 'package:aihu_getx_app/utils/constants.dart';
import 'package:aihu_getx_app/widgets/common_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class VipUserListItemWidget extends StatelessWidget {
  final VipUserRespVO data;

  VipUserListItemWidget(this.data, {super.key});

  final _statusSwitch = true.obs;

  @override
  Widget build(BuildContext context) {
    _statusSwitch.value = data.status == 0;
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(top: 1),
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: Row(
        children: [
          CommonImage(
            TextUtil.isEmpty(data.avatar) ? Constants.icon : data.avatar,
            fit: BoxFit.cover,
            width: 110,
            height: 110,
            isCircle: true,
          ),
          const SizedBox(width: 10),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text("${data.id}"),
                Text(
                  "${data.nickname}",
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  style: const TextStyle(
                    fontSize: 22,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                Text("${data.mobile}"),
                Obx(
                  () => CupertinoSwitch(
                    value: _statusSwitch.value,
                    onChanged: (v) {
                      data.status = v ? 0 : 1;
                      Get.find<DMemberVipuserIndexController>()
                          .updateUser(data)
                          .then(
                            (value) => _statusSwitch.value = v,
                          );
                    },
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
